<?php


namespace app\erp\model;


use think\Model;

class MonthContractdb extends Model
{
    protected $name = 'month_contract';
    protected $pk = 'id';

    public $param = [];
    protected $append = ['supplier_name','audit_name'];


    public function getSupplierNameAttr($val,$row){
        return Memberdb::where('member_id',$row['supplier_id'])->value('supplier_name');
    }

    public function getAuditNameAttr($val,$row){
        if($row['audit_id']){
            return Memberdb::where('member_id',$row['audit_id'])->value('username');
        } else {
            return '';
        }
    }

    public function base($query){
        if(isset($this->param['month']) && $this->param['month']){
            $query->where('month',$this->param['month']);
        }
        if(isset($this->param['audit']) && $this->param['audit'] != ''){
            $query->where('audit',$this->param['audit']);
        }
        if(isset($this->param['supplier_id']) && $this->param['supplier_id']){
            $query->where('supplier_id',$this->param['supplier_id']);
        }
    }
}